package fp.thetrainline.screens;

import fp.thetrainline.utils.DriverSupport;
import fp.thetrainline.utils.ElementName;
import fp.thetrainline.utils.ElementType;

public class PlanJourney {

	public static void searchStation( DriverSupport driver, String from, String to )  {
		driver.click( ElementType.ID, ElementName.FROM_STATION );
		writeStation( driver, from );
	
		driver.click( ElementType.ID, ElementName.TO_STATION );
		writeStation( driver, to );
	}
	
	public static void returnJourney( DriverSupport driver )  {
		driver.click( ElementType.XPATH, ElementName.RETURN_BUTTON );
	}
	
	public static void now( DriverSupport driver )  {
		driver.click( ElementType.LINK, ElementName.NOW );
	}
	
	public static void getTrainTimes( DriverSupport driver )  {
		driver.click( ElementType.XPATH, ElementName.GET_TRAIN_TIMES_BUTTON );
	}
	
	public static void selectOutwardDay( DriverSupport driver, String value ) {
		selectValue( driver, ElementName.OUTWARD_DATE_DAY, value );
	}
	
	public static void selectOutwardHour( DriverSupport driver, String value ) {
		selectValue( driver, ElementName.OUTWARD_DATE_HOUR, value );
	}
	
	public static void selectOutwardMin( DriverSupport driver, String value ) {
		selectValue( driver, ElementName.OUTWARD_DATE_MIN, value );
	}
	
	public static void selectReturnDay( DriverSupport driver, String value ) {
		selectValue( driver, ElementName.RETURN_DATE_DAY, value );
	}
	
	public static void selectReturnHour( DriverSupport driver, String value ) {
		selectValue( driver, ElementName.RETURN_DATE_HOUR, value );
	}
	
	public static void selectReturnMin( DriverSupport driver, String value ) {
		selectValue( driver, ElementName.RETURN_DATE_MIN, value );
	}
	
	private static void writeStation( DriverSupport driver, String station )  {
		driver.write( ElementType.ID, ElementName.SEARCH_BY_NAME_TEXT_FIELD, station );
		driver.click( ElementType.CSS, ElementName.SEARCH_BUTTON );
	}
	
	private static void selectValue( DriverSupport driver, String name, String value ) {
		driver.selectValue( ElementType.ID, name, value );
	}
	
}
